package com.qiqidream.admin.system.service.impl;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.TypeReference;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qiqidream.admin.common.utils.tree.TreeUtil;
import com.qiqidream.admin.system.mapper.DepartmentMapper;
import com.qiqidream.admin.system.model.entity.Department;
import com.qiqidream.admin.system.model.vo.DepartmentVo;
import com.qiqidream.admin.system.service.DepartmentService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author QiQiDream
 * @since 2019/12/11 20:42
 */
@Service
public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Department> implements DepartmentService {
    @Override
    public List<DepartmentVo> getDepartments() {
        List<Department> departmentList = list();
        List<DepartmentVo> convert = Convert.convert(new TypeReference<List<DepartmentVo>>() {}, departmentList);
        return TreeUtil.getTreeList(0L, convert);
    }

    @Override
    public Boolean removeDepartment(Long id) {
        List<Long> ids = baseMapper.getChildrenId(id);
        ids.add(id);
        return removeByIds(ids);
    }
}
